/*****************************************************************
**                                                             	**
**  Copyright (C) 2004 Amlogic,Inc.                            	**
**  All rights reserved                                        	**
**        Filename : MoviePlayBack.c /Project:AVOS		       **
**        Revision : 1.1                                       	**
**                                                             	**
*****************************************************************/
#include "../menu.h"
#include "MoviePlayBackEvent.h"
#include "NetmenuSetupEvent.h"
#include "../../user.h"

INT32S WinMoviePlayBackMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return WinMoviePlayBackOnShow(hwnd, lpParam) ;
            
        case WM_KEYDOWN:
        	return WinMoviePlayBackOnKeyPress(hwnd, lpParam);
		default:
			break;
    }
    return 0 ;
}

void SetWinMoviePlayBackPalette_720P(void)
{
    YUVENTRY mask_para[4] = {0,120,4095,4095};
    
    AWSetAlphaMask(1,4, mask_para);
    AWSetAlphaMask(2,4, mask_para);
    AWSetAlphaMask(3,4, mask_para);
    YUVENTRY palette_para[16] = {0x8000 | 15208,0x8000 | 16216,0x8000 | 17880,0x8000 | 16392,16280,16184,16088,16040,16024,15880,15208,15720,15016,15064,15304,15144};
    AWSetPalette(1,16, palette_para);
    AWSetPalette(2,16, palette_para);
    AWSetPalette(3,16, palette_para);
    return ;
}

void SetWinMoviePlayBackPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    switch(CurOsdSize){
		case OsdSize720p:
            RECT NormalWindowRect = {0,0,1280,720};
            pControl->winrect = NormalWindowRect;
            CREATEWINDOWPARAM NormalWindowPara = {3,{{240,640,800,32},
            {1000,60,120,32},
        #ifdef AVI_SUBTITLE_ZOOM
            {240,520,800,120},
        #else
            {380,560,512,70},
        #endif
            {0,0,0,0}},
            {PF_PALETTE_256,PF_PALETTE_256,PF_PALETTE_256,0},SetWinMoviePlayBackPalette_720P};
            AWSendMessage(pControl, WM_WINDOW_RESET_DRAW_AREA, (INT32S)&NormalWindowPara);
            break ;
    }//end of switch
    return;
}

HWND *CreateControlWinMoviePlayBack_720P(HWND* pParent,INT8U CurOsdSize)
{
    HWND* pNewControl;
    switch(CurOsdSize){
		case OsdSize720p:
            CREATEWINDOWPARAM Normalwindow_para = {3,{{240,640,800,32},
                          {1000,60,120,32},
                    #ifdef AVI_SUBTITLE_ZOOM
                          {240,520,800,120},
                    #else
                          {380,560,512,70},
                    #endif
                          {0,0,0,0}},
                          {PF_PALETTE_256,PF_PALETTE_256,PF_PALETTE_256,0},SetWinMoviePlayBackPalette_720P};
            //Create Menu Window -- 1
            pNewControl = AWCreateWinControl("TWindow","WinMoviePlayBack_720P",WS_OVERLAPPEDWINDOW,
		                      0,0,0,0,NULL, (INT32S)&Normalwindow_para,WinMoviePlayBackMsgProc_720P) ;
            pNewControl->win_id = 0 ;
            break ;
                        
    }//end of switch
            return pNewControl;
}

INT32S MoviePlayInfoBarMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
	switch( msg_type){
		case WM_SHOWWINDOW:
			return MoviePlayInfoBarOnShow(hwnd,lpParam);
		case WM_HIDEWINDOW:
			AWClearRectTxt(hwnd->winrect.left, hwnd->winrect.top, hwnd->winrect.width, hwnd->winrect.height) ;
			break;
		case WM_KEYDOWN:
			return MoviePlayInfoBarOnKeyPress(hwnd, lpParam) ;
					
		default:
			return WinMoviePlayBackHide(hwnd, msg_type, lpParam);
	}
	
	return 0;		
}

void SetMoviePlayInfoBarPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
		case OsdSize720p:
            pControl->winrect.top = pControl->parent->winrect.top + 640;
            pControl->winrect.left = pControl->parent->winrect.left + 240;
            pControl->winrect.width = 800;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 11;
            RECT NormalDrawRect[11] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,800,32},
            {pControl->winrect.left + 60, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 120, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 200, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 280, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 360, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 420, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 500, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 580, pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 630 + 40,pControl->winrect.top + 0,90,32},
            {pControl->winrect.left + 630 + 40,pControl->winrect.top + 8,90,32},
            };
            for(iLoop=0; iLoop < 11; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

HWND *CreateControlMoviePlayInfoBar_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- MoviePlayInfoBar_720P
    HWND *pNewControl;
    switch(CurOsdSize){
		case OsdSize720p:
            pNewControl = AWCreateWinControl("TControl","MoviePlayInfoBar_720P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      240,640,800,32,pParent,0,MoviePlayInfoBarMsgProc_720P) ;
            pNewControl->win_id = 1 ;
            pNewControl->draw_info_num = 11;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[11] = {
                          {0,0,0,0,(INT32U)ICON_INFOBAR_STATUS512,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_PREV_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_INFOBAR_FB_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_PAUSE_FOCUS_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_INFOBAR_FF_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_NEXT_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_STOP_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_ZOOM_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_SUB_LOSE_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)ICON_INFOBAR_PLAYTIME_BACKGROUND_2,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)infobar_time_str,DT_STRING_DATA}};            	

            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

INT32S MoviePlayStateMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_KEYDOWN:
        	return MoviePlayStateOnKeyPress(hwnd, lpParam);
		case WM_HIDEWINDOW:
			AWClearRectTxt(hwnd->winrect.left, hwnd->winrect.top, hwnd->winrect.width, hwnd->winrect.height) ;
			break;
		default:
			break;

    }
    return 0 ;
}

void SetMoviePlayStatePos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
		case OsdSize720p:
            pControl->winrect.top = pControl->parent->winrect.top + 60;
            pControl->winrect.left = pControl->parent->winrect.left + 1000;
            pControl->winrect.width = 120;
            pControl->winrect.height = 32;
            pControl->draw_info_num = 4;
            RECT NormalDrawRect[4] = {
            {pControl->winrect.left + 0,pControl->winrect.top + 0,120,32},
            {pControl->winrect.left + 32,pControl->winrect.top + 0,32,32},
            {pControl->winrect.left + 64,pControl->winrect.top + 0,10,32},
            {pControl->winrect.left + 74,pControl->winrect.top + 0,16,32},
            };
            for(iLoop=0; iLoop < 4; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

HWND *CreateControlMoviePlayState_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- MoviePlayState
    HWND *pNewControl;
    switch(CurOsdSize){
		case OsdSize720p:
            pNewControl = AWCreateWinControl("TControl","MoviePlayState_720P",(WS_CHILDWINDOW | WS_CHILDWINDOW),
		                      1000,60,120,32,pParent,0,MoviePlayStateMsgProc_720P) ;
            pNewControl->win_id = 4 ;
            pNewControl->draw_info_num = 4;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[4] = {
                          {0,0,120,32,(INT32U)ICON_INFOBAR_STATUS1,DT_RLE_BMP_DATA},
                          {0,0,32,32,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,10,32,(INT32U)0,DT_RLE_BMP_DATA},
                          {0,0,16,32,(INT32U)0,DT_RLE_BMP_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;       
                        
    }//end of switch
            return pNewControl;
}

void SetAviSubCtrlPos_720P(HWND* pControl, INT8U CurOsdSize)
{
    int iLoop;
    switch(CurOsdSize){
		case OsdSize720p:
        #ifdef AVI_SUBTITLE_ZOOM
            pControl->winrect.top = pControl->parent->winrect.top + 520;
            pControl->winrect.left = pControl->parent->winrect.left + 240;
            pControl->winrect.width = 800;
            pControl->winrect.height = 120;
        #else
            pControl->winrect.top = pControl->parent->winrect.top + 560;
            pControl->winrect.left = pControl->parent->winrect.left + 380;
            pControl->winrect.width = 512;
            pControl->winrect.height = 70;
        #endif
            pControl->draw_info_num = 3;
            RECT NormalDrawRect[3] = {
        #ifdef AVI_SUBTITLE_ZOOM
	     {pControl->winrect.left + 0,pControl->winrect.top + 0,800,120},
            {pControl->winrect.left + 0,pControl->winrect.top + 0,800,60},
            {pControl->winrect.left + 0,pControl->winrect.top + 60,800,60},
            };
    #else
	     {pControl->winrect.left + 0,pControl->winrect.top + 0,512,70},
            {pControl->winrect.left + 0,pControl->winrect.top + 8,512,30},
            {pControl->winrect.left + 0,pControl->winrect.top + 38,512,30},
            };
    #endif
            for(iLoop=0; iLoop < 3; iLoop++)
                memcpy(&(pControl->draw_info[iLoop]), &NormalDrawRect[iLoop], sizeof(RECT));
            break ;
    }//end of switch
    return;
}

INT32S AviSubCtrlMsgProc_720P(PHWND hwnd, INT32U msg_type, INT32S lpParam)
{
    switch( msg_type){
        case WM_SHOWWINDOW:
            return AviSubCtrlOnShow(hwnd, lpParam) ;
	 case WM_HIDEWINDOW:
	     return AviSubCtrlOnHide(hwnd, lpParam) ;
    }
    return 0 ;
}

HWND *CreateControlAviSubCtrl_720P(HWND *pParent,INT8U CurOsdSize)
{
    //Create Control -- AviSubCtrl
    HWND *pNewControl;
    switch(CurOsdSize){
		case OsdSize720p:		
        #ifdef AVI_SUBTITLE_ZOOM
            pNewControl = AWCreateWinControl("TControl","AviSubCtrl_720P",(WS_CHILDWINDOW | WS_DISVISIBLE),
		                      240,520,800,120,pParent,0,AviSubCtrlMsgProc_720P) ;
        #else
            pNewControl = AWCreateWinControl("TControl","AviSubCtrl_720P",(WS_CHILDWINDOW | WS_DISVISIBLE),
		                      380,560,512,70,pParent,0,AviSubCtrlMsgProc_720P) ;
        #endif
            pNewControl->win_id = 3 ;
            pNewControl->draw_info_num = 3;
            pNewControl->draw_info = (PDRAWINFO)AVMem_umalloc(sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            DRAWINFO NormalDrawDatas[3] = {
			     {0,0,0,0,(INT32U)ICON_SUB_BLANK_PLBK,DT_RLE_BMP_DATA},
                          {0,0,0,0,(INT32U)sub_txt_line1,DT_STRING_DATA},
                          {0,0,0,0,(INT32U)sub_txt_line2,DT_STRING_DATA}};
            memcpy(pNewControl->draw_info,NormalDrawDatas, sizeof(DRAWINFO) * pNewControl->draw_info_num) ;
            break ;
    }//end of switch
            return pNewControl;
}

HWND* CreateMenuWinMoviePlayBack_720P(void)
{
    HWND *pNewControl ;
    TWINDOWS *pWin;
    HWND *pWinMoviePlayBack_720P = CreateControlWinMoviePlayBack_720P(NULL,CurrentOsdSize);
    SetWinMoviePlayBackPos_720P(pWinMoviePlayBack_720P,CurrentOsdSize);

    pNewControl= CreateControlMoviePlayInfoBar_720P(pWinMoviePlayBack_720P,CurrentOsdSize);
    SetMoviePlayInfoBarPos_720P(pNewControl,CurrentOsdSize);

    pNewControl= CreateControlMoviePlayState_720P(pWinMoviePlayBack_720P,CurrentOsdSize);
    SetMoviePlayStatePos_720P(pNewControl,CurrentOsdSize);

    pNewControl=CreateControlAviSubCtrl_720P(pWinMoviePlayBack_720P,CurrentOsdSize);
    SetAviSubCtrlPos_720P(pNewControl,CurrentOsdSize);

    pWin = (TWINDOWS *)pWinMoviePlayBack_720P;
    pWin->pFocusControl = AWFindWinCtrlByName("MoviePlayInfoBar_720P");
    return pWinMoviePlayBack_720P;
}

void WinResetWinMoviePlayBackControlsPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    switch(pControl->win_id){
        case 0://WinMoviePlayBack_720P
            SetWinMoviePlayBackPos_720P(pControl,CurOsdSize) ;
            break ;
        case 1://MoviePlayInfoBar_720P
            SetMoviePlayInfoBarPos_720P(pControl,CurOsdSize) ;
            break ;
        case 2://MoviePlayState_720P
            SetMoviePlayStatePos_720P(pControl,CurOsdSize) ;
            break ;
        case 3://AviSubCtrl_720P
            SetAviSubCtrlPos_720P(pControl,CurOsdSize) ;
            break ;
    }//end of switch
}
void WinResetWinMoviePlayBackPos_720P(HWND *pControl, INT8U CurOsdSize)
{
    HWND *pChildControl;
    if(pControl == NULL)
        pControl = AWFindWinCtrlByName("WinMoviePlayBack_720P");
    if(pControl == NULL) return ;

    WinResetWinMoviePlayBackControlsPos_720P(pControl, CurOsdSize) ;
    pChildControl = pControl->children ;
    while(pChildControl != NULL){
    	WinResetWinMoviePlayBackPos_720P(pChildControl, CurOsdSize) ;
    	pChildControl = pChildControl->siblings ;
	}
	return ;
}

